<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>登录日志列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="../../../common/js/public.js"></script>
    <script type="text/javascript" src="../../../common/js/publicUtils.js"></script>

</head>
<body>
<div class="layui-fluid" id="flowDiv">
    <div class="zTreeBackground right" style="padding-left:1%;width:98%">
        <div class="layui-form-item" style="width:99%;margin-bottom:-10px;text-align:right;">
            <div class="layui-inline">
                <label class="layui-form-label">登录名</label>
                <div class="layui-input-block">
                    <input type="text" id="loginNameQuery"  autocomplete="off" class="layui-input" placeholder="请输入登录名"/>
                    <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="easysearch()"></i>
                </div>
            </div>
            <button type="button" style="margin-left:12px;margin-top: -12px;" class="layui-btn layui-btn-normal" onclick="moresearch()"><i class="layui-icon layui-icon-search"></i>高级搜索</button>
        </div>
        <div class="search_float_div" style="position:absolute;z-index:999;width:99%;background-color: #f1f1f1;padding-top: 20px;text-align:left;display:none">
            <div class="layui-form-item">
                        <label class="layui-form-label">ip地址</label>
                        <div class="layui-input-inline">
                            <input type="text" id="ipAdress" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">登录时间</label>
                        <div class="layui-input-inline">
                            <input type="text" id="loginTime" autocomplete="off" class="layui-input">
                        </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="searchTable()"><i class="layui-icon layui-icon-search"></i>查询</button>
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="resetSearchTable()"><i class="layui-icon layui-icon-search"></i>重置</button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="canclesearch()">取消</button>
                </div>
            </div>
        </div>
        <table class="layui-hide" id="datatable" lay-filter="datatable"></table>
        <script type="text/html" id="toolbar"></script>

    </div>

</div>
</body>
<SCRIPT type="text/javascript">
    $(function(){
        loadbutton("toolbar");//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        loadTable();
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#loginTime' //指定元素
                ,type: 'datetime'
                ,range: true
            });
        });
    })
    /* *
     * @Description 高级搜索
     * @return
     */
    function moresearch(){
        $(".search_float_div").slideToggle();
    }
    /* *
     * @Description 简单查询
     * @return
     */
    function easysearch(){
        var loginName = $("#loginNameQuery").val();
        loadTable(loginName);

    }
    /* *
     * @Description 取消查询
     * @return
     */
    function canclesearch(){
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Description 重置查询
     * @return
     */
    function resetSearchTable(){
        $("#loginName").val("");
        $("#ipAdress").val("");
        $("#loginTime").val("");
        searchTable();
    }
    /* *
     * @Description 搜索table数据
     * @return
     */
    function searchTable(){
        loadTable($("#loginName").val(),$("#ipAdress").val(),$("#loginTime").val());
        $(".search_float_div").slideToggle();//关闭搜素div
    }

    /* *
    * @Description 初始化table
    * @return
    */
    function loadTable(loginName,ipAdress,loginTime){

        var beginTime = "";
        var endTime = "";
        if(loginTime){
            beginTime = loginTime.split(" - ")[0];
            endTime = loginTime.split(" - ")[1];
        }
        var tableurl = publicUrl+'system/loginlog/list';
        layui.use(['form','table','element'], function(){
            var element = layui.element;
            form = layui.form;
            table = layui.table;
            tableObj = table.render({
                elem: '#datatable',
                size: 'sm',
                toolbar: '#toolbar',
                even: true, //开启隔行背景
                height: 'full-100',
                method: 'post',
                headers: {"Authorization":getData("Authorization")},
                url: tableurl, //stationId='+window.parent.window.parentId,//8AE7DECA-8E41-4FAB-8B30-9FD1B0B7FA33,78A9E5D8-20FB-4436-BBE8-A25EAC38D056
                where:{
                        loginName :  loginName,
                        ipAdress :  ipAdress,
                        'params[beginLoginTime]' :  beginTime,
                        'params[endLoginTime]' :  endTime
                },
                response: {
                    statusCode: 2000,
                },
                parseData: function(res){ //res 即为原始返回的数据
                    return formatTableParseData(res);
                },
                request: {
                    pageName: 'pageIndex' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                cols: [[
                    {
                        type:'checkbox',
                        width: 60,
                    },
                    {
                        type: 'numbers',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },
                    {
                        field: 'loginName',
                        title: '登录名',
                        sort: true,
                        align: 'center',
                    },
                    {
                        field: 'loginType',
                        title: '登录类型',
                        sort: true,
                        align: 'center',
                    },
                    {
                        field: 'deviceName',
                        title: '设备名称',
                        sort: true,
                        align: 'center',
                    },
                    {
                        field: 'ipAdress',
                        title: 'ip地址',
                        sort: true,
                        align: 'center',
                    },
                    {
                        field: 'loginTime',
                        title: '登录时间',
                        sort: true,
                        align: 'center',
                        templet:function(r){
                            return g_FormatDate(new Date(r.loginTime),'yyyy-MM-dd hh:mm:ss');
                        }
                    },
                ]],
                page: true
            });
            // //监听行双击事件
            table.on('rowDouble(data-table)', function(obj){
                show(obj);
            });
            element.render();
        });
    }

    //显示详情
    function show(obj){
        var url='./edit.html?id='+obj.data.id;
        layer.open({
            type: 2,
            area: ["40%" , "80%"],
            fix: false,
            //不固定
            shade: 0.3,
            title: "查看登录日志信息",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            cancel: function(index) {
                return true;
            }
        });
    }

    /**
     * @Description 添加工艺工法
     * @return
     **/
    function add(){
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["40%" , "80%"],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "新增登录日志",
            content: "./add.html",
            btn: ['应用','确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.submit();//应用
                if(resultdata && resultdata.code==2000){
                    loadTable();
                }
                return false;
                //layer.closeAll();
            },
            btn2: function(index, layero){
                //按钮【按钮二】的回调
                var resultdata = iframeWin.contentWindow.submit();//保存
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    layer.closeAll();
                }else{
                    return false;
                }
            },
            btn3: function(index, layero){

            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
            }
        });
    }

    /**
     * @Description 修改工艺工法页面
     * @return
     **/
    function edit(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行修改！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["40%" , "80%"],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "编辑登录日志",
            content: "./edit.html?id="+data.id,
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.submit();
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    layer.closeAll();
                }else {
                    return false;
                }
            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
            }
        });
    }



    /* *
     * @Description 删除记录
     * @return
     */
    function  deleteRow() {
        //获取选中项
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length<1){
            layer.alert("请至少选择一项信息！");
            return false;
        }
        var ids = new Array();
        for(var i=0;i<obj.data.length;i++){
            ids.push(obj.data[i].id);
        }
        layui.use(['layer'],function(){
            var layer = layui.layer;
            layer.confirm('确定删除？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(){
                var delurl = 'system/loginlog/delete';
                var data = {"ids":ids.join(",")};//删除
                publicAjax (null,delurl,data,null,null,function (r) {
                    if(r.code==2000){
                        laysuccess("删除成功",null);
                        loadTable();
                    }else{
                        layerror("删除失败",null);
                    }
                });
            }, function(){
                layer.closeAll();

            });
        })
    }

    function uploadFile(){
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["500px" , "350px"],
            fix: false,
            //不固定
            shade: 0.3,
            title: "登录日志导入",
            content: "./import.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.init();
            }
        });
    }


</script>
</html>